package com.openbravo.pos.payment;

import com.openbravo.editor.JEditorCurrencyPositive;
import com.openbravo.editor.JEditorKeys;
import com.openbravo.format.Formats;
import com.openbravo.pos.customers.CustomerInfoExt;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.util.RoundUtils;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

public class JPaymentDebt extends JPanel
  implements JPaymentInterface
{
  private JPaymentNotifier notifier;
  private CustomerInfoExt customerext;
  private double m_dPaid;
  private double m_dTotal;
  private JLabel jLabel12;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JLabel jLabel6;
  private JLabel jLabel8;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JPanel jPanel3;
  private JPanel jPanel4;
  private JPanel jPanel5;
  private JPanel jPanel6;
  private JScrollPane jScrollPane1;
  private JTextArea jlblMessage;
  private JEditorKeys m_jKeys;
  private JLabel m_jMoneyEuros;
  private JTextField m_jName;
  private JTextArea m_jNotes;
  private JEditorCurrencyPositive m_jTendered;
  private JTextField txtCurdate;
  private JTextField txtCurdebt;
  private JTextField txtMaxdebt;

  public JPaymentDebt(JPaymentNotifier paramJPaymentNotifier)
  {
    this.notifier = paramJPaymentNotifier;
    initComponents();
    this.m_jTendered.addPropertyChangeListener("Edition", new RecalculateState( ));
    this.m_jTendered.addEditorKeys(this.m_jKeys);
  }

  public void activate(CustomerInfoExt paramCustomerInfoExt, double paramDouble, String paramString)
  {
    this.customerext = paramCustomerInfoExt;
    this.m_dTotal = paramDouble;
    this.m_jTendered.reset();
    if (paramCustomerInfoExt == null)
    {
      this.m_jName.setText(null);
      this.m_jNotes.setText(null);
      this.txtMaxdebt.setText(null);
      this.txtCurdate.setText(null);
      this.txtCurdebt.setText(null);
      this.m_jKeys.setEnabled(false);
      this.m_jTendered.setEnabled(false);
    }
    else
    {
      this.m_jName.setText(paramCustomerInfoExt.getName());
      this.m_jNotes.setText(paramCustomerInfoExt.getNotes());
      this.txtMaxdebt.setText(Formats.CURRENCY.formatValue(Double.valueOf(RoundUtils.getValue(paramCustomerInfoExt.getMaxdebt()))));
      this.txtCurdate.setText(Formats.DATE.formatValue(paramCustomerInfoExt.getCurdate()));
      this.txtCurdebt.setText(Formats.CURRENCY.formatValue(Double.valueOf(RoundUtils.getValue(paramCustomerInfoExt.getCurdebt()))));
      if (RoundUtils.compare(RoundUtils.getValue(paramCustomerInfoExt.getCurdebt()), RoundUtils.getValue(paramCustomerInfoExt.getMaxdebt())) >= 0)
      {
        this.m_jKeys.setEnabled(false);
        this.m_jTendered.setEnabled(false);
      }
      else
      {
        this.m_jKeys.setEnabled(true);
        this.m_jTendered.setEnabled(true);
        this.m_jTendered.activate();
      }
    }
    printState();
  }

  public PaymentInfo executePayment()
  {
    return new PaymentInfoTicket(this.m_dPaid, "debt");
  }

  public Component getComponent()
  {
    return this;
  }

  private void printState()
  {
    if (this.customerext == null)
    {
      this.m_jMoneyEuros.setText(null);
      this.jlblMessage.setText(AppLocal.getIntString("message.nocustomernodebt"));
      this.notifier.setStatus(false, false);
    }
    else
    {
      Double localDouble = this.m_jTendered.getDoubleValue();
      if ((localDouble == null) || (localDouble.doubleValue() == 0.0D))
        this.m_dPaid = this.m_dTotal;
      else
        this.m_dPaid = localDouble.doubleValue();
      this.m_jMoneyEuros.setText(Formats.CURRENCY.formatValue(new Double(this.m_dPaid)));
      if (RoundUtils.compare(RoundUtils.getValue(this.customerext.getCurdebt()) + this.m_dPaid, RoundUtils.getValue(this.customerext.getMaxdebt())) >= 0)
      {
        this.jlblMessage.setText(AppLocal.getIntString("message.customerdebtexceded"));
        this.notifier.setStatus(false, false);
      }
      else
      {
        this.jlblMessage.setText(null);
        int i = RoundUtils.compare(this.m_dPaid, this.m_dTotal);
        this.notifier.setStatus((this.m_dPaid > 0.0D) && (i <= 0), i == 0);
      }
    }
  }

  private void initComponents()
  {
    this.jPanel5 = new JPanel();
    this.jPanel4 = new JPanel();
    this.jLabel8 = new JLabel();
    this.m_jMoneyEuros = new JLabel();
    this.jLabel3 = new JLabel();
    this.m_jName = new JTextField();
    this.jLabel12 = new JLabel();
    this.jLabel2 = new JLabel();
    this.txtMaxdebt = new JTextField();
    this.jLabel4 = new JLabel();
    this.txtCurdebt = new JTextField();
    this.jLabel6 = new JLabel();
    this.txtCurdate = new JTextField();
    this.jScrollPane1 = new JScrollPane();
    this.m_jNotes = new JTextArea();
    this.jPanel6 = new JPanel();
    this.jlblMessage = new JTextArea();
    this.jPanel2 = new JPanel();
    this.jPanel1 = new JPanel();
    this.m_jKeys = new JEditorKeys();
    this.jPanel3 = new JPanel();
    this.m_jTendered = new JEditorCurrencyPositive();
    setLayout(new BorderLayout());
    this.jPanel5.setLayout(new BorderLayout());
    this.jPanel4.setLayout(null);
    this.jLabel8.setText(AppLocal.getIntString("label.debt"));
    this.jPanel4.add(this.jLabel8);
    this.jLabel8.setBounds(20, 20, 100, 15);
    this.m_jMoneyEuros.setBackground(new Color(153, 153, 255));
    this.m_jMoneyEuros.setHorizontalAlignment(4);
    this.m_jMoneyEuros.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(UIManager.getDefaults().getColor("Button.darkShadow")), BorderFactory.createEmptyBorder(1, 4, 1, 4)));
    this.m_jMoneyEuros.setOpaque(true);
    this.m_jMoneyEuros.setPreferredSize(new Dimension(150, 25));
    this.jPanel4.add(this.m_jMoneyEuros);
    this.m_jMoneyEuros.setBounds(120, 20, 150, 25);
    this.jLabel3.setText(AppLocal.getIntString("label.name"));
    this.jPanel4.add(this.jLabel3);
    this.jLabel3.setBounds(20, 70, 100, 15);
    this.m_jName.setEditable(false);
    this.jPanel4.add(this.m_jName);
    this.m_jName.setBounds(120, 70, 200, 19);
    this.jLabel12.setText(AppLocal.getIntString("label.notes"));
    this.jPanel4.add(this.jLabel12);
    this.jLabel12.setBounds(20, 100, 100, 15);
    this.jLabel2.setText(AppLocal.getIntString("label.maxdebt"));
    this.jPanel4.add(this.jLabel2);
    this.jLabel2.setBounds(20, 180, 100, 15);
    this.txtMaxdebt.setEditable(false);
    this.txtMaxdebt.setHorizontalAlignment(4);
    this.jPanel4.add(this.txtMaxdebt);
    this.txtMaxdebt.setBounds(120, 180, 130, 19);
    this.jLabel4.setText(AppLocal.getIntString("label.curdebt"));
    this.jPanel4.add(this.jLabel4);
    this.jLabel4.setBounds(20, 210, 100, 15);
    this.txtCurdebt.setEditable(false);
    this.txtCurdebt.setHorizontalAlignment(4);
    this.jPanel4.add(this.txtCurdebt);
    this.txtCurdebt.setBounds(120, 210, 130, 19);
    this.jLabel6.setText(AppLocal.getIntString("label.curdate"));
    this.jPanel4.add(this.jLabel6);
    this.jLabel6.setBounds(20, 240, 100, 15);
    this.txtCurdate.setEditable(false);
    this.txtCurdate.setHorizontalAlignment(0);
    this.jPanel4.add(this.txtCurdate);
    this.txtCurdate.setBounds(120, 240, 130, 19);
    this.m_jNotes.setEditable(false);
    this.jScrollPane1.setViewportView(this.m_jNotes);
    this.jPanel4.add(this.jScrollPane1);
    this.jScrollPane1.setBounds(120, 100, 200, 70);
    this.jPanel5.add(this.jPanel4, "Center");
    this.jlblMessage.setBackground(UIManager.getDefaults().getColor("Label.background"));
    this.jlblMessage.setEditable(false);
    this.jlblMessage.setLineWrap(true);
    this.jlblMessage.setWrapStyleWord(true);
    this.jlblMessage.setFocusable(false);
    this.jlblMessage.setPreferredSize(new Dimension(300, 72));
    this.jlblMessage.setRequestFocusEnabled(false);
    this.jPanel6.add(this.jlblMessage);
    this.jPanel5.add(this.jPanel6, "South");
    add(this.jPanel5, "Center");
    this.jPanel2.setLayout(new BorderLayout());
    this.jPanel1.setLayout(new BoxLayout(this.jPanel1, 1));
    this.jPanel1.add(this.m_jKeys);
    this.jPanel3.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.jPanel3.setLayout(new BorderLayout());
    this.jPanel3.add(this.m_jTendered, "Center");
    this.jPanel1.add(this.jPanel3);
    this.jPanel2.add(this.jPanel1, "North");
    add(this.jPanel2, "East");
  }

  private class RecalculateState
    implements PropertyChangeListener
  {
    private RecalculateState()
    {
    }

    public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
    {
      JPaymentDebt.this.printState();
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.JPaymentDebt
 * JD-Core Version:    0.6.0
 */